import dayjs from 'dayjs'

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    m1:{
      type: Object,
      default:() => ({})
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    noDataChartList:[],
    noDataChartStr:"",
    chargingVoltageInfo:{}, //放电电压
    chargingEleInfo:{},     //放电电流
    bmsaccuracyInfo:{},     //BMS精度
    chargingTempInfo:{},    //放电温差
    hstMaxTempInfo:{},      //最高温度历史
    hstTempDiffInfo:{},     //温差历史曲线
    hstTempRateInfo:{},     //温升历史曲线
    hstMaxVolInfo:{},       //最高单体电压历史曲线
    hstVoltDiffInfo:{},     //压差历史曲线
    hstOCVInfo:{},          //开路电压一致性
    hstsocaccuracyInfo:{},  //SOC准确度历史曲线
    chargespeedInfo:{}      //放电功率
  },

  /**
   * 组件的方法列表
   */
  methods: {
    dealDataFixed(dataList){
      let arr = []
      dataList.map((item) => {
        arr.push(item.toFixed(2));
      });
      return arr
    }
  },

  observers:{
    'm1': function (dataInfo){
      console.log("dataInfo>>>", dataInfo)

      // 收集小于4个数据的图表
      let noDataChartList = []
      let noDataChartStr = ""
      // 放电电压曲线
      let chargingVoltageInfo = {
        showChart: dataInfo.volttime && dataInfo.volttime.length > 3,
        noticeInfo: dataInfo.voltinfo,
        resultInfo: dataInfo.voltEvalResult,
        resultStatus: dataInfo.voltState,
        chartData:{
          xDataList: dataInfo.volttime || [],
          yDataList: [
            // {
            //   name: "需求电压",
            //   data:dataInfo.requiredvolt 
            // },
            {
              name: "放电电压",
              data:dataInfo.measuredvolt
            }
          ],
          yAxisName:'电压(V)'
        }
      }
      if(dataInfo.volttime && dataInfo.volttime.length < 4){
        noDataChartList.push("放电电压曲线")
      }
      
      // 放电电流曲线
      let chargingEleInfo = {
        showChart: dataInfo.currenttime && dataInfo.currenttime.length > 3,
        noticeInfo: dataInfo.currentinfo,
        resultInfo: dataInfo.currentEvalResult,
        resultStatus: dataInfo.currentState,
        chartData:{
          xDataList: dataInfo.currenttime || [],
          yDataList: [
            // {
            //   name: "需求电流",
            //   data:dataInfo.requiredcurrent 
            // },
            {
              name: "放电电流",
              data:dataInfo.measuredcurrent
            }
          ],
          yAxisName:'电流(A)'
        }
      }
      if(dataInfo.currenttime && dataInfo.currenttime.length < 4){
        noDataChartList.push("放电电流曲线")
      }

      // BMS测量精度曲线
      let bmsaccuracyInfo = {
        showChart: dataInfo.bmsaccuracytime && dataInfo.bmsaccuracytime.length > 3,
        noticeInfo: dataInfo.bmsaccuracyinfo,
        resultInfo: dataInfo.bmsaccuracyEvalResult,
        resultStatus: dataInfo.bmsaccuracyState,
        chartData:{
          xDataList: dataInfo.bmsaccuracytime || [],
          yDataList: [
            {
              name: "电流精度",
              data:dataInfo.bmsaccuracycurrent 
            },
            {
              name: "电压精度",
              data:dataInfo.bmsaccuracyvolt
            }
          ],
          yAxisName:'%'
        }
      }
      if(dataInfo.volttime && dataInfo.volttime.length < 4){
        noDataChartList.push("BMS测量精度曲线")
      }

      // 放电温差曲线
      let chargingTempInfo = {
        showChart: dataInfo.tempdifftime && dataInfo.tempdifftime.length > 3,
        noticeInfo: dataInfo.tempdiffinfo,
        resultInfo: dataInfo.tempdiffEvalResult,
        resultStatus: dataInfo.tempdiffState,
        chartData:{
          xDataList: dataInfo.tempdifftime || [],
          yDataList: [
            {
              name: "放电温差",
              data:dataInfo.difftemp 
            },
          ],
          yAxisName:'温度(°C)',
          min: function (value) {
            return value.min > 2 ? Math.round(value.min - 2) : 0;
          },
          max: function (value) {
            return Math.round(value.max + 2);
          },
        }
      }
      if(dataInfo.tempdifftime && dataInfo.tempdifftime.length < 4){
        noDataChartList.push("放电温差曲线")
      }

      // 最高温度历史曲线
      let hstMaxTempInfo = {
        showChart: dataInfo.hstmaxtemptime && dataInfo.hstmaxtemptime.length > 3,
        noticeInfo: dataInfo.hstmaxtempinfo,
        resultInfo: dataInfo.hstmaxtempEvalResult,
        chartData:{
          xDataList: dataInfo.hstmaxtemptime ? dataInfo.hstmaxtemptime.reverse() : [],
          yDataList: [
            {
              name: "最高温度",
              data: dataInfo.hstmaxtemp ? dataInfo.hstmaxtemp.reverse() : [] 
            },
          ],
          yAxisName:'最高温度(℃)',
          min: function (value) {
            return Math.round(value.min - 2);
          },
          max: function (value) {
            return Math.round(value.max + 2);
          },
        }
      }
      if(dataInfo.hstmaxtemptime && dataInfo.hstmaxtemptime.length < 4){
        noDataChartList.push("最高温度历史曲线")
      }

      // 温差历史曲线
      let hstTempDiffInfo = {
        showChart: dataInfo.hsttempdifftime && dataInfo.hsttempdifftime.length > 3,
        noticeInfo: dataInfo.hsttempdiffinfo,
        resultInfo: dataInfo.hsttempdiffEvalResult,
        resultStatus: dataInfo.hsttempdiffState,
        chartData:{
          xDataList: dataInfo.hsttempdifftime ? dataInfo.hsttempdifftime.reverse() : [],
          yDataList: [
            {
              name: "放电温差",
              data:dataInfo.hsttempdiff ? dataInfo.hsttempdiff.reverse() : []
            },
          ],
          yAxisName:'温度(°C)',
          min: function (value) {
            return value.min > 2 ? Math.round(value.min - 2) : 0;
          },
          max: function (value) {
            return Math.round(value.max + 2);
          },
        }
      }
      if(dataInfo.hsttempdifftime && dataInfo.hsttempdifftime.length < 4){
        noDataChartList.push("温差历史曲线")
      }

      // 温升历史曲线
      let hstTempRateInfo = {
        showChart: dataInfo.hsttempRatetime && dataInfo.hsttempRatetime.length > 3,
        noticeInfo: dataInfo.hsttempRateinfo,
        chartData:{
          xDataList: dataInfo.hsttempRatetime ? dataInfo.hsttempRatetime.reverse() : [],
          yDataList: [
            {
              name: "升温速率",
              data:dataInfo.hsttempRate ? dataInfo.hsttempRate.reverse() : []
            },
          ],
          yAxisName:'升温速率',
          min: function (value) {
            return Math.round(value.min - 2);
          },
          max: function (value) {
            return Math.round(value.max + 2);
          },
        }
      }
      if(dataInfo.hsttempRatetime && dataInfo.hsttempRatetime.length < 4){
        noDataChartList.push("温升历史曲线")
      }

      // 最高单体电压历史曲线
      let hstMaxVolInfo = {
        showChart: dataInfo.hstmaxvolttime && dataInfo.hstmaxvolttime.length > 3,
        noticeInfo: dataInfo.hstmaxvoltinfo,
        resultInfo: dataInfo.hstmaxvoltEvalResult,
        chartData:{
          xDataList: dataInfo.hstmaxvolttime ? dataInfo.hstmaxvolttime.reverse() : [],
          yDataList: [
            {
              name: "电压曲线",
              data:dataInfo.hstmaxvolt ? dataInfo.hstmaxvolt.reverse() : []
            },
          ],
          yAxisName:'单体电压(V)',
        }
      }
      if(dataInfo.hstmaxvolttime && dataInfo.hstmaxvolttime.length < 4){
        noDataChartList.push("最高单体电压历史曲线")
      }

      // 压差历史曲线
      // let hstVoltDiffInfo = {
      //   showChart: dataInfo.hstvoltdifftime && dataInfo.hstvoltdifftime.length > 3,
      //   noticeInfo: dataInfo.hstvoltdiffinfo,
      //   resultInfo: dataInfo.hstvoltdiffEvalResult,
      //   resultStatus: dataInfo.hstvoltdiffState,
      //   chartData:{
      //     xDataList: dataInfo.hstvoltdifftime ? dataInfo.hstvoltdifftime.reverse() : [],
      //     yDataList: [
      //       {
      //         name: "压差历史曲线",
      //         data:dataInfo.hstvoltdiff ? dataInfo.hstvoltdiff.reverse() : []
      //       },
      //     ],
      //     yAxisName:'压差(V)',
      //   }
      // }
      // if(dataInfo.hstvoltdifftime && dataInfo.hstvoltdifftime.length < 4){
      //   noDataChartList.push("压差历史曲线")
      // }

      // 开路电压一致性历史曲线
      // let hstOCVInfo = {
      //   showChart: dataInfo.hstOCVtime && dataInfo.hstOCVtime.length > 3,
      //   noticeInfo: dataInfo.hstOCVinfo,
      //   resultInfo: dataInfo.hstOCVEvalResult,
      //   resultStatus: dataInfo.hstOCVState,
      //   chartData:{
      //     xDataList: dataInfo.hstOCVtime ? dataInfo.hstOCVtime.reverse() : [],
      //     yDataList: [
      //       {
      //         name: "一致性",
      //         data:dataInfo.hstOCV ? dataInfo.hstOCV.reverse() : []
      //       },
      //     ],
      //     yAxisName:'分',
      //   }
      // }
      // if(dataInfo.hstOCVtime && dataInfo.hstOCVtime.length < 4){
      //   noDataChartList.push("开路电压一致性历史曲线")
      // }

      // SOC准确度历史曲线
      let hstsocaccuracyInfo = {
        showChart: dataInfo.hstsocaccuracytime && dataInfo.hstsocaccuracytime.length > 3,
        noticeInfo: dataInfo.hstsocaccuracyinfo,
        resultInfo: dataInfo.hstsocaccuracyEvalResult,
        resultStatus: dataInfo.hstsocaccuracyState,
        chartData:{
          xDataList: dataInfo.hstsocaccuracytime ? dataInfo.hstsocaccuracytime.reverse() : [],
          yDataList: [
            {
              name: "SOC准确度历史曲线",
              data:dataInfo.hstsocaccuracy ? this.dealDataFixed(dataInfo.hstsocaccuracy).reverse() : []
            },
          ],
          yAxisName:'%',
        }
      }
      if(dataInfo.hstsocaccuracytime && dataInfo.hstsocaccuracytime.length < 4){
        noDataChartList.push("SOC准确度历史曲线")
      }

      // 放电功率
      let arrPower = []
      if(dataInfo.power){
        dataInfo.power.map((item) => {
          item = item / 1000;
          arrPower.push(item.toFixed(2));
        });
      }

      let chargespeedInfo = {
        showChart: dataInfo.cdsdTime && dataInfo.cdsdTime.length > 3,
        noticeInfo: dataInfo.chargespeedinfo,
        chartData:{
          xDataList: dataInfo.cdsdTime ? dataInfo.cdsdTime : [],
          yDataList: [
            {
              name: "放电功率",
              data:dataInfo.power ? arrPower : []
            },
          ],
          yAxisName:'放电功率(kW)',
        }
      }
      if(dataInfo.cdsdTime && dataInfo.cdsdTime.length < 4){
        noDataChartList.push("放电功率")
      }


      console.log("noDataChartList>>>", noDataChartList)
      noDataChartStr = noDataChartList.join('、')
      this.setData({
        noDataChartList,
        noDataChartStr,
        chargingVoltageInfo,
        chargingEleInfo,
        bmsaccuracyInfo,
        chargingTempInfo,
        hstMaxTempInfo,
        hstTempDiffInfo,
        hstTempRateInfo,
        hstMaxVolInfo,
        // hstVoltDiffInfo,
        // hstOCVInfo,
        hstsocaccuracyInfo,
        chargespeedInfo
      })
    }
  }
})
